//
//  MineHeadview.m
//  K8彩票
//
//  Created by zhoubo on 2017/7/7.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "MineHeadview.h"

#import <Masonry.h>
#import "ContactViewController.h"
#import "AboutViewController.h"
#import "LuckyLotteryViewController.h"
#import <MessageUI/MessageUI.h>
#import "DutyViewController.h"
#import "MineHeadview.h"
#import "Head.h"
#import "DataManager.h"

@interface MineHeadview ()
@property (weak, nonatomic) IBOutlet UIView *viewTopbg;
@property (weak, nonatomic) IBOutlet UIImageView *imagePhoto;

@property (weak, nonatomic) IBOutlet UISwitch *switchApply;
@property (weak, nonatomic) IBOutlet UISwitch *pushswitch;

@property (nonatomic,strong) DataManager* dataManager;
@end

@implementation MineHeadview

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(void)awakeFromNib
{
    [super awakeFromNib];
    self.dataManager = [DataManager newInstance];
    [self initializeView];
}

- (IBAction)pushSwitch:(UISwitch*)sender {
    
    if(sender.on==YES){
        NSLog(@"开关被打开");
        [self.dataManager saveBoolCache:@"is_open_push" value:NO];
    }else{
        NSLog(@"开关被关闭");
        [self.dataManager saveBoolCache:@"is_open_push" value:YES];
    }
    
}

- (void)initializeView{

    
    
    _viewTopbg.layer.cornerRadius = 8;
    //    _imagePhoto.layer.cornerRadius = 25;
    
    UILabel *_labelActivity = [[UILabel alloc]initWithFrame:CGRectMake(0, 80, ScreenWidth() - 30, 40)];
    [_viewTopbg addSubview:_labelActivity];
    [_labelActivity setText:NSLocalizedString(@"彩票小助手", @"彩票小助手")];
    [_labelActivity setBackgroundColor:[UIColor whiteColor]];
    [_labelActivity setFont:[UIFont systemFontOfSize:15]];
    _labelActivity.textAlignment = NSTextAlignmentCenter;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_labelActivity.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = _labelActivity.bounds;
    maskLayer.path = maskPath.CGPath;
    _labelActivity.layer.mask = maskLayer;
    
    
    _switchApply.on = IS_OPEN_SWITCH;
    _pushswitch.on = IS_OPEN_PUSH;
    [_switchApply addTarget:self action:@selector(swChange:) forControlEvents:UIControlEventValueChanged];
    
    [_imagePhoto setImage:[UIImage imageNamed:@"profile01"]];
    _imagePhoto.layer.cornerRadius = 25;
    _imagePhoto.layer.masksToBounds = YES;

    
}

- (void) swChange:(UISwitch*) sw{
    if(sw.on==YES){
        NSLog(@"开关被打开");
        [self.dataManager saveBoolCache:@"is_open_switch" value:NO];
    }else{
        NSLog(@"开关被关闭");
        [self.dataManager saveBoolCache:@"is_open_switch" value:YES];
    }
}



@end
